package basicprocess;

import java.util.Hashtable;
import java.util.Vector;



import utility.CapitalChar;
import utility.Input;

import database.RecordSearch;
import dbmanager.Column;
import dbmanager.DBManager;
import dbmanager.GetIdName;


public class  Basicprocess 
{
	DBManager database;
	Hashtable<Object, Object>Mastermap= new Hashtable<Object, Object>();
	Vector< Object>propertyVector = new Vector<Object>();
	String BASICPROCESS="basicprocess";
	String TYPE="type";
	GetIdName gid;
	RecordSearch sr;
	Object object;
	Vector<Object>processVector = new Vector<Object>();
	Basicprocessinterface process;
	Hashtable<Object, Object>Basichashtable =new Hashtable<Object, Object>();
	
	public Basicprocess() 
	{
	
	}
	
	public void setDbmanager(DBManager database)
	{
	 this.database = database;
	 gid = new GetIdName(database);
	 BASICPROCESS = gid.getId(BASICPROCESS);
	 TYPE = gid.getId(TYPE);
	 sr =new RecordSearch(database);
	}
	
	public void setObject(Object object)
	{
		this.object =object;	
	}
	
	public void processBasicprocess()
	{
		Hashtable< Object, Object>table = new Hashtable<Object, Object>();
		table.put("pid",TYPE);
		table.put("pv",BASICPROCESS);
		table.put("td", "null");
		sr.setConditionMap(table);
		String line[]=sr.getArrayFromResultSet();
		for(int i=0;i<line.length;i++)
		{
			String splitstring[] = line[i].split("\t");
			String classname = splitstring[Column.mid_index-1];
			classname = gid.getItem(classname);			
			try 
			{
				Class C = Class.forName("basicprocess."+CapitalChar.makeFirstCharCapital(classname));
				process = (Basicprocessinterface)C.newInstance();
				process.setDbmanager(database);
				process.setObject(object);
				process.processBasicprocess(); 
				processVector.add(this);
				Basichashtable.putAll(process.getHashtable());
			}
			catch (ClassNotFoundException e) 
			{
				e.printStackTrace();
			}
			catch (InstantiationException e) 
			{
				e.printStackTrace();
			}
			catch (IllegalAccessException e) 
			{
				e.printStackTrace();
			}
			
		}
	}

	public Hashtable<Object, Object> getMasterHashtabel() 
	{
		return this.Mastermap;
	}

	public Vector<Object> getpropertydetailsVector() 
	{
		return this.propertyVector;
	}

	public void getInsert()
	{
		for(int i=0;i<processVector.size();i++)
		{
			Basicprocess basicprocess = (Basicprocess) processVector.get(i);
			basicprocess.process.getInsert();
		}
	}

	public void getUpdate()
	{
		for(int i=0;i<processVector.size();i++)
		{
			Basicprocess basicprocess = (Basicprocess) processVector.get(i);
			basicprocess.process.getUpdate();
		}
	}
	
	public Hashtable<Object, Object> getHashtable() 
	{	
		return Basichashtable;
	}
		

}
